package com.sky.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.annotation.Resource;

/**
 * WebSocket配置类，用于注册WebSocket的Bean
 */
@Configuration
public class WebSocketConfiguration {

    @Resource
    private Environment environment;

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        // 判断当前是否为测试环境
        String[] activeProfiles = environment.getActiveProfiles();
        for (String profile : activeProfiles) {
            if ("test".equals(profile)) {
                // 测试环境返回null，不创建该Bean
                return null;
            }
        }
        // 非测试环境正常创建
        return new ServerEndpointExporter();
    }


}
